<template>

	<view class="content" style="overflow: hidden;">
		<view class="header">
			<image src="" mode="" ></image>
			<input disabled="disabled" class="search" type="text" value="" placeholder="请输入搜索内容" @tap='$open("/pages/index/searchcomm/searchcomm")'/>
			<view></view>
		</view>
		<view class="page-body" :style="'height:'+height+'px'">
			<scroll-view class="nav-left" scroll-y 
			 scroll-with-animation>
				<view class="nav-left-item" @click="categoryClickMain(index,item.id)"  :key="index" :class="index== pid || pid == item.id?'active':''"
				 v-for="(item,index) in classifyData">
					{{item.name}}
				</view>
			</scroll-view>
			<view class="list_tap">
				<scroll-view class="list_tap_item" scroll-x 
				 scroll-with-animation>
					<text v-for="item in twocalsify" :key='item.catid' :class=" catid == item.catid ?'active':'' "  @tap='twothree(item.catid)'>{{item.name}}</text>
				</scroll-view>
				<!-- 筛选 -->
				<view class="list_tap_items">
					<view class="list_tap_sec" @click="listDate">
						<text>价格</text>
						<image :src="size? '../../static/images/a5.png':'../../static/images/a6.png'" mode=""></image>
					</view>
					<view class="list_tap_sec" @click="showSize">
						<text>销量</text>
						<image :src="size0? '../../static/images/a5.png':'../../static/images/a6.png'" mode=""></image>
					</view>
					<view class="list_tap_sec">
						<text>热卖</text>
						<!-- <image :src="src" mode=""></image> -->
					</view>
					<view class="list_tap_sec" @click="change">
						<text>时间</text>
						<image :src="size1? '../../static/images/a5.png':'../../static/images/a6.png'" mode=""></image>

					</view>
				</view>
			</view>
			<scroll-view class="nav-right" scroll-y  :style="'height:'+height+'px' "
			 scroll-with-animation>
				<view class="box" v-for="item in goodlist" :key='item.id'>
					<image :src="item.goods_image" mode=""></image>
					<view class="box_list">
						<text>{{item.title}}</text>
						<text>{{item.title_f}}</text>
						<view class="box_item">
							<text>￥{{item.price}}</text>
							<image src="../../static/images/a4.png" mode="" @tap='cart(item.id)'></image>
						</view>
					</view>
				</view>

			</scroll-view>
		</view>

	</view>
</template>

<script>
	// import classifyData from '../../common/classify.data.js';
	export default {
		data() {
			return {
				add:'',
				size: false,
				size0: false,
				size1: false,
				name: "wkiwi",
				height: 0,
				categoryActive: 0,
				// scrollTop: 0,
				// scrollLeftTop: 0,
				// scrollHeight: 0,
				//一级分类
				classifyData: [],
				//二级
				twocalsify:[],
				//商品列表
				goodlist:[],
				//全局分类ID
				pid:0,
				catid:0,
			 courrt:1,
			 name:'',
			 value:'',
			 price:'',
			 ishot:'',
			 xl:'',
			 time:'',
				id:'',
				flag:true
			
			}
		},
		created() {
			//如果你的分类数据为后台异步获取请	将下方代码放置你的数据回调中
			// this.$nextTick(()=>{
			// 	this.getHeightList();
			// })
		},
		onLoad() {
			uni.$on('classifys',(id)=>{
			       this.id = id;  
						  console.log(this.id)
			   })  
				
		
		},
		onShow(options) {
			
			var a = uni.getStorageSync('abc');
			if(a){
				uni.setStorageSync('abc','');
				this.pid=uni.getStorageSync('pid');
				this.catid=uni.getStorageSync('catid');
				//一级分类
				this.cl()
				this.twosld(this.pid)
				this.twothree(this.catid)
			}else{
				
				//一级分类
				this.cl()
				//二级分类
				this.two()
				//商品列表
				this.goodList()
					
				}
			// uni.setTabBarBadge({
			// 	index: 3,
			// 	text: '0'
			// })
			this.height = uni.getSystemInfoSync().windowHeight - this.tabBarHeight;
		},
		onReachBottom(){
			if(this.flag){
				this.$ajax(
				this.apiList.goodlist,
				{
					pid:this.pid,
					catid:this.catid,
					page:++this.courrt,
					price:this.price,
					ishot:this.ishot,
					time:this.time,
					xl:this.xl
				},
				"POST",
				).then(res=>{
					if(!res.data.length){
						this.flag = false
						this.$sToast('无更多数据')
					}
				this.goodlist = this.goodlist.concat(res.data) 
				})
			}
				
		},
		methods: {
			//left一级分类
			cl(){
				this.$ajax(
					this.apiList.clasify,
				'POST',
				).then(res=>{
				this.classifyData	 = res.data
				// console.log(res)
				})
			},
			//二级分类
			two(){
				this.$ajax(
				this.apiList.twocalify,
				'POST',
				).then(res=>{
					this.twocalsify = res.data
				
				})
			},
			//商品列表
			goodList(){
				this.$ajax(
				this.apiList.goodlist,
				'POST',
				).then(res=>{
					this.goodlist = res.data
				})
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 时间排序
			change() {
				 this.size1 = !this.size1
				 this.courrt = 0
				 this.ishot='';
				 this.time='';
				 this.xl='';
				 if(this.size1){
				 	this.price='asc'
				 }else{
				 	this.price='desc'
				 }
				 // this.size1 = !this.size1
				 this.$ajax(
				 this.apiList.goodlist,
				 {
				 	pid:this.pid,
				 	catid:this.catid,
				 	price:this.time
				 },
				 "POST"
				 ).then(res=>{
				 	this.goodlist = res.data
				 })
			},
			// 价格排序
			listDate() {
				this.size = !this.size
				this.courrt = 0
				this.ishot='';
				this.time='';
				this.xl='';
				if(this.size){
					this.price='asc'
				}else{
					this.price='desc'
				}
				// this.size1 = !this.size1
				this.$ajax(
				this.apiList.goodlist,
				{
					pid:this.pid,
					catid:this.catid,
					price:this.price
				},
				 "POST"
				).then(res=>{
					this.goodlist = res.data
				})
			},
			//销量排序
			showSize() {
				this.size0 = !this.size0
			
				this.courrt = 0
				this.ishot='';
				this.time='';
				this.xl='';
				if(this.size0){
					this.price='asc'
				}else{
					this.price='desc'
				}
				// this.size1 = !this.size1
				this.$ajax(
				this.apiList.goodlist,
				{
					pid:this.pid,
					catid:this.catid,
					price:this.xl
				},
				 "POST"
				).then(res=>{
					this.goodlist = res.data
				})
			},
	
			//一级分类
			twosld(id){
				this.$ajax(
				this.apiList.twocalify,
				{
				pid:id
				},
				"POST",
				).then(res=>{
				this.twocalsify	= res.data
				})
				
				this.$ajax(
				this.apiList.goodlist,
				{
				pid:id
				},
				"POST",
				).then(res=>{
				this.goodlist = res.data
				})
			},
			//一级分类
			categoryClickMain(index,id) {
				this.courrt =1
				this.pid = id
				this.catid = 0
				this.twosld(id)
				this.categoryActive = index;
				// this.scrollTop == this.arr[index] ? this.scrollTop = this.scrollTop + 1 : this.scrollTop = this.arr[index] //防止两次相等造成点击不触发滚动时间
			},
			
			//二级分类
			twothree(id){
				this.courrt =1
			this.catid = id
				this.$ajax(
				this.apiList.goodlist,
				{
				pid:this.pid,
				catid:id,
				},
				"POST",
				).then(res=>{
					this.goodlist = res.data
				
				})
			},
			cart(id){
				this.$ajax(
				this.apiList.cart,
				{
					gid:id
				},
				'POST'
				).then(res=>{
					this.$sToast(res.msg)	
					//购物车徽标
					 uni.setTabBarBadge({
					     index: 3,
					     text: res.num
					    })
	
				})
			
			}
		
		},
		
		
		components: {}
	}
</script>

<style lang="scss">
	.content {
		margin-top: 0rpx;
		box-sizing: border-box;
		.header {
			position: fixed;
			width: 100%;
			z-index: 99999;
			height: 150rpx;
			display: flex;
			align-items: center;
			background: #8BDD8E;
			justify-content: space-between;
			
			image {
				width: 18rpx;
				height: 32rpx;
				padding-left: 30rpx;
				margin-top: 50rpx;
			}

			.search {
				width: 70%;
				height: 48rpx;
				margin-top: 50rpx;
				background-color: rgba(245, 245, 245, 1) !important;
				border-radius: 32rpx;
				padding-left: 80rpx;
				box-sizing: border-box;
				background: url(../../static/images/s14.png) no-repeat;
				background-position: 33%;
				background-size: 6%;
				text-align: center;
				font-size: 24rpx;
			}
		}
	}

	.page-body {
		display: flex;
		background: #fff;
		overflow: hidden;
		margin-top: 9%;
		background: #fff;
		z-index: 9999;
		.list_tap {
			position: fixed;
			left: 25%;
			margin-top: 80rpx;
			z-index: 999;
			background: #fff;
			width: 73%;
			height: 80rpx;
			.list_tap_items {
				position: absolute;
				top: 90%;
				background: #fff;
				width: 73%;
				padding-bottom: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.list_tap_sec {
					font-size: 24rpx;
					color: #616161;
					margin-left: 20rpx;
					image {
						width: 10rpx;
						height: 20rpx;
						margin-left: 10rpx;
					}
				}
			}
			.list_tap_item {
				text {
					padding: 7rpx 20rpx;
					margin-left: 20rpx;
					background: #F5F5F5;
					color: #9E9E9E;
					font-size: 24rpx;
				}
			}


		}
	}

	.nav {
		display: flex;
		width: 100%;
	}
	.nav-left {
		width: 25%;
		background: #fafafa;
		height: 100vh;
		border-right: 1px solid #f5f5f5;
		// padding-bottom:100upx;
		position: fixed;
		top: 140rpx;
	}

	.nav-left-item {
		height: 100rpx;
		border-right: solid 1px #f1f1f1;
		border-bottom: solid 1px #f1f1f1;
		font-size: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.nav-left-item:last-child {
		border-bottom: none;
	}

	.nav-right {
		width: 75%;
		// margin-top: 120rpx;
		z-index: 1;
		position: relative;
		left: 25%;
		top: 210rpx;
		// left: 25%;
		height: 79%;
		margin-bottom: 0;
	}
	.box {
		// position: absolute;
		width: 100%;
		display: flex;
		padding: 20rpx;
		// height: 175rpx;
		border-bottom: 1px solid #F5F5F5;
		
		/*若您的子分类过少想使得每个子分类占满屏请放开上边注视 */
		image {
			width: 160rpx;
			height: 160rpx;
		}
		.box_list {
			margin-left: 20rpx;
			width: 60%;
			text {
				display: block;
				font-size: 26rpx;
			}
		}

		.box_item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 55rpx;

			text {
				font-size: 26rpx;
				color: red;
			}

			image {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}

	.box:last-child {
		border: none;
		height: 80%;
	}

	.nav-right-item {
		display: flex;
		width: 100%;
		float: left;
		text-align: center;
		padding: 11rpx;
		font-size: 28rpx;
		background: #fff;
	}

	.nav-right-item image {
		width: 150rpx;
		height: 150rpx;
	}

	.active {
		color: #8BDD8E;
		background: #fff;
		border-right: 0;
		border-left: 3px solid #8BDD8E;
	}

	::-webkit-scrollbar {
		/*取消小程序的默认导航条样式*/
		width: 0;
		height: 0;
		color: transparent;
	}

</style>
